// 日志管理
import { commonEditForm, commonQuery, commonVisible, commonOptions } from '@/api/config';
export const sysLogLoginMixin = {
    data() {
        return {
            query: {
                order: "",
                orderField: "",
                pageIndex: 1,
                pageSize: 20,
                creatorName: "",
                status: ""
            },
            tableData: [
                {
                    id: "",
                    operation: "",
                    status: "成功",
                    userAgent: "",
                    ip: "",
                    creatorName: "",
                    createDate: ""
                }
            ],
            multipleSelection: [],
            delList: [],
            pageTotal: 0,
            idx: -1
        };
    },
    methods: {
        // 获取数据
        getSysLLData({
            order = this.query.order,
            orderField = this.query.orderField,
            page = this.query.pageIndex,
            limit = this.query.pageSize,
            creatorName = this.query.creatorName,
            status = this.query.status,
            _t = Date.now()
        }) {
            this.$axios
                .get("/sys/log/login/page", {
                    params: {
                        order,
                        orderField,
                        page,
                        limit,
                        creatorName,
                        status,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        this.$message.error(res.msg);
                    }
                    // console.log(res);
                    this.pageTotal = res.data.total || 0;
                    this.tableData = res.data.list;
                    this.tableData.map(item => {
                        item.operation = item.operation === 0 ? "登录" : "退出";
                        item.status = item.status === 1 ? "成功" : "失败";
                    });
                })
                .catch(() => { });
        }
    }

}


export const sysLogOperation = {
    data() {
        return {
            query: {
                status: "",
                pageIndex: 1,
                pageSize: 20
            },
            tableData: [
                {
                    id: "",
                    operation: "",
                    requestUri: "",
                    requestMethod: "",
                    requestParams: "",
                    requestTime: "",
                    userAgent: "",
                    ip: "",
                    status: "",
                    creatorName: "",
                    createDate: null
                }
            ],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            idx: -1
        };
    },
    methods: {
        // 获取数据
        getSLOData({
            order = "",
            orderField = "",
            page = this.query.pageIndex,
            limit = this.query.pageSize,
            status = this.query.status,
            _t = Date.now()
        }) {
            this.$axios
                .get("/sys/log/operation/page", {
                    params: {
                        order,
                        orderField,
                        page,
                        limit,
                        status,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    // console.log(res);
                    this.pageTotal = res.data.total || 0;
                    this.tableData = res.data.list;
                    this.tableData.map(item => {
                        item.status = item.status === 1 ? "成功" : "失败";
                        item.requestTime = item.requestTime + "ms";
                    });
                });
        }
    }
}


export const sysLogErrorMixin = {
    data() {
        return {
            query: {
                order: "",
                orderField: "",
                pageIndex: 1,
                pageSize: 20
            },
            tableData: [
                {
                    id: "",
                    requestUri: "",
                    requestMethod: "",
                    requestParams: null,
                    userAgent: "",
                    ip: "",
                    errorInfo: "",
                    createDate: null
                }
            ],
            errVisible: false,
            pageTotal: 0,
            form: {
                errorInfo: "111"
            }
        };
    },
    methods: {
        // 获取数据
        getSLEData({
            order = this.query.order,
            orderField = this.query.orderField,
            page = this.query.pageIndex,
            limit = this.query.pageSize,
            _t = Date.now()
        }) {
            this.$axios
                .get("/sys/log/error/page", {
                    params: {
                        order,
                        orderField,
                        page,
                        limit,
                        _t
                    }
                })
                .then(({ data: res }) => {
                    if (res.code !== 0) {
                        return this.$message.error(res.msg);
                    }
                    this.pageTotal = res.data.total || 0;
                    this.tableData = res.data.list;
                })
                .catch(() => { });
        }
    }
}